﻿using CommonEntity;
using CommonLibary;
using NetCore6WebAPITestOneEntity;
using NetCroe6WebAPITestOneResponse;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Serialization;

namespace NetCroe6WebAPITestOneBusiness
{

    public class WeatherForecastBusiness : BaseBusiness
    {
        WeatherForecastResponse _weatherForecastResponse;
        WebClientSingletonHelper _webClientHelper;

        public WeatherForecastBusiness(LoggerSingletonHelper loggerSingletonHelper, WeatherForecastResponse weatherForecastResponse, WebClientSingletonHelper webClientHelper) : base(loggerSingletonHelper)
        {
            _weatherForecastResponse = weatherForecastResponse;
            _webClientHelper = webClientHelper;
        }

        public object XmlSerializerAnimaTest() {
            var xmlSerial = new XmlSerializer(typeof(AnimalsModel));
            using (var xmlSource = new FileStream("animals.xml", FileMode.Open))
            {
                return xmlSerial.Deserialize(xmlSource);
            }
        }

        public object XmlSerializerXlmnsTest()
        {
            var xmlSerial = new XmlSerializer(typeof(ReturnOrderOutModel));

            using (var xmlSource = new FileStream("xmlSource.xml", FileMode.Open))
            {
                return xmlSerial.Deserialize(xmlSource);
            }
        }

        public async Task<ViewModelBase> HttpClientTest(string url,string token)
        {
            return await DoFuncAsync<ViewModelBase>(async () =>
            {
                string rtData =await _webClientHelper.ClientGetAsync(url, token);
                return new ViewModelBase()
                {
                    code = HttpStatusCode.OK,
                    data = rtData
                };
            });
        }
    }
}
